home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HAM Radio 1997
/
HAM Radio 1997.iso
/
vcls
/
moden
/
adport.int
< prev
next >
Wrap
Text File
|
1996-04-08
|
26KB
|
688 lines
{Conditional defines that may affect this unit}
{$I AWDEFINE.INC}
{Required options}
{$G+,X+,F+}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
{*********************************************************}
{* ADPORT.PAS 1.01 *}
{* Copyright (c) TurboPower Software 1995 *}
{* All rights reserved. *}
{*********************************************************}
unit AdPort;
{-Delphi serial port component}
interface
uses
{!!.01 modified}
{-----RTL}
WinTypes,
WinProcs,
SysUtils,
Classes,
Messages,
Controls,
DsgnIntf,
Forms,
{-----APD}
OoMisc,
{$IFNDEF UseAPWDLL}
AwUser,
{$ENDIF}
AwComm,
AwFossil,
AdMisc,
AdExcept,
AdPEdit0;
{$IFDEF UseAPWDLL}
{$I AWPORT.PA0} {Data/procedure/function declarations}
{$I AWUSER.PA0} {Procedure/function declarations}
{$ENDIF}
type
{Parity type}
TParity = (pNone, pOdd, pEven, pMark, pSpace);
{Activation procedure type}
TActivationProcedure = procedure;
{Device layer types}
TDeviceLayer = (dlNone, dlComm, dlFossil, dlOther);
{Baud type}
TBaudRate = LongInt;
{Hardware flow control types}
THWFlowOptions = (
hwfUseDTR, {Use DTR for receive flow control}
hwfUseRTS, {Use RTS for receive flow control}
hwfRequireDSR, {Require DSR before transmittting}
hwfRequireCTS); {Require CTS before transmittting}
THWFlowOptionSet = set of THWFlowOptions;
{Software flow control types}
TSWFlowOptions = (swfNone, swfReceive, swfTransmit, swfBoth);
{For reporting flow states, note: no rcv hardware flow status is provided}
TFlowControlState = (fcOff, {No flow control is in use}
fcOn, {Transmit blocked}
fcDsrHold, {Transmit blocked by low DSR}
fcCtsHold, {Transmit blocked by low CTS}
fcDcdHold, {Transmit blocked by low DCD}
fcXOutHold, {Transmit blocked by Xoff}
fcXInHold, {Receive blocked by Xoff}
fcXBothHold); {Both are blocked by Xoff}
{Tracing/logging states}
TTraceLogState = (tlOff, tlOn, tlDump, tlAppend, tlClear, tlPause);
{General trigger event handler}
TTriggerEvent = procedure(CP : TObject;
Msg, TriggerHandle, Data : Word) of object;
{Specific trigger event handlers}
TTriggerAvailEvent = procedure(CP : TObject; Count : Word) of object;
TTriggerDataEvent = procedure(CP : TObject; TriggerHandle : Word) of object;
TTriggerStatusEvent = procedure(CP : TObject;
TriggerHandle : Word) of object;
TTriggerTimerEvent = procedure(CP : TObject; TriggerHandle : Word) of object;
{Status event handlers}
TTriggerLineErrorEvent = procedure(CP : TObject;
Error : Word;
LineBreak : Boolean) of object;
{WaitChar event handler}
TWaitCharEVent = procedure(CP : TObject; C : Char) of object;
{Port open/close callbacks}
TPortCallback = procedure(CP : TObject; Opening : Boolean) of object;
{Dispatcher modes}
TDispatcherMode = (
dNone, {Failed to enable dispatcher}
dTimer, {Use the timer only}
dCommEvents, {Use 3.1 style comm events and a timer}
dAuto);
{For keeping track of port users} {!!.01}
PUserListEntry = ^TUserListEntry; {!!.01}
TUserListEntry = record {!!.01}
Handle : THandle; {!!.01}
OpenClose : TPortCallback; {!!.01}
end; {!!.01}
{$I OOMISC.PA2} {Contains types for OOPORT/ADPORT}
const
{Message values, duplicated from OOMISC}
APW_TRIGGERAVAIL = OOMISC.apw_TriggerAvail;
APW_TRIGGERDATA = OOMISC.apw_TriggerData;
APW_TRIGGERTIMER = OOMISC.apw_TriggerTimer;
APW_TRIGGERSTATUS = OOMISC.apw_TriggerStatus;
{Modem status trigger options, duplicated from OOMISC}
msCTSDelta = $0010;
msDSRDelta = $0020;
msRingDelta = $0004;
msDCDDelta = $0080;
{Line status trigger options, duplicated from OOMISC}
lsOverrun = $0001;
lsParity = $0002;
lsFraming = $0004;
lsBreak = $0008;
{Line and driver errors, duplicated from OOMISC}
leNoError = 0; {No error, ordinal value matches ecOK}
leBuffer = 1; {Buffer overrun in COMM.DRV}
leOverrun = 2; {UART receiver overrun}
leParity = 3; {UART receiver parity error}
leFraming = 4; {UART receiver framing error}
leCTSTO = 5; {Transmit timeout waiting for CTS}
leDSRTO = 6; {Transmit timeout waiting for DSR}
leDCDTO = 7; {Transmit timeout waiting for RLSD}
leTxFull = 8; {Transmit queue is full}
leBreak = 9; {Break condition received}
{Status trigger subtypes, duplicated from OOMISC}
stNone = 0; {not active}
stModem = 1; {Trigger on modem status change}
stLine = 2; {Trigger on line status change}
stOutBuffFree = 3; {Trigger on outbuff free level}
stOutBuffUsed = 4; {Trigger on outbuff used level}
stOutSent = 5; {Trigger on any PutXxx call}
{Parity strings}
ParityName : array[TParity] of String[5] =
('None', 'Odd', 'Even', 'Mark', 'Space');
{Property defaults}
DefDeviceLayer = dlComm;
DefComHandle = 0;
DefComNumber = 2;
DefBaud = 19200;
DefParity = pNone;
DefDatabits = 8;
DefStopbits = 1;
DefInSize = 4096;
DefOutSize = 4096;
DefOpen = False;
DefAutoOpen = True;
DefDispatcherMode = dTimer;
DefDTR = True;
DefRTS = True;
DefTracing = tlOff;
DefTraceSize = 10000;
DefTraceName = 'APD.TRC';
DefTraceHex = True;
DefLogging = tlOff;
DefLogSize = 10000;
DefLogName = 'APD.LOG';
DefLogHex = True;
DefUseMSRShadow = True;
DefForceGets = False;
DefUseEventWord = True;
DefHWFlowOptions = [];
DefSWFlowOptions = swfNone;
DefXonChar = #17;
DefXoffChar = #19;
DefBufferFull = 0;
DefBufferResume = 0;
DefTriggerLength = 1;
DefCommNotificationLevel = 10;
type
{.Z+}
{Baud rate property editor}
TBaudRateProperty = class(TIntegerProperty)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;
{.Z-}
{Port component}
TApdCustomComPort = class(TComponent)
protected {private}
{.Z+}
{Internal stuff}
Force : Boolean; {True to force property setting}
TriggerHandler : TNotifyProc; {Internal trigger handler}
IsOpen : Boolean; {True if physically open}
OkToOpen : Boolean; {True if port was loaded}
ForceOpen : Boolean; {Force open after loading}
UserList : TList; {List of comport users}
CopyTriggers : Boolean; {Copy triggers on open} {!!.01}
SaveTriggers : TTriggerSave; {Triggers to copy} {!!.01}
{Port info}
FDeviceLayer : TDeviceLayer; {Device layer for this port}
FComHandle : TComHandle; {Handle to comm object}
FComNumber : Word; {Com1 - ComWhatever}
FBaud : LongInt; {Baud rate}
FParity : TParity; {Parity}
FDatabits : Word; {Data bits}
FStopbits : Word; {Stop bits}
FInSize : Word; {Input buffer size}
FOutSize : Word; {Output buffer size}
FOpen : Boolean; {True if the port is open}
FAutoOpen : Boolean; {True to do implicit opens}
FDispatcherMode : TDispatcherMode; {Dispatcher mode}
FActivateDevice : TActivationProcedure; {Proc to activate device layer}
FCommNotificationLevel : Word; {Comm notify level}
{Modem control/status}
FDTR : Boolean; {DTR control state}
FRTS : Boolean; {RTS control state}
{Flow control}
FBufferFull : Word; {Flow control cutoff}
FBufferResume : Word; {Flow control resume}
FHWFlowOptions : THWFlowOptionSet; {Hardware flow control}
FSWFlowOptions : TSWFlowOptions; {Software flow control}
FXOnChar : Char; {Xon character}
FXOffChar : Char; {Xoff character}
{Debugging}
FTracing : TTraceLogState; {Controls Tracing state}
FTraceSize : Word; {Number of tracing entries}
FTraceName : String; {Name of trace file}
FTraceHex : Boolean; {True to dump trace in hex}
FLogging : TTraceLogState; {Controls DispatchLogging state}
FLogSize : Word; {Size, in bytes, of log buffer}
FLogName : String; {Name of log file}
FLogHex : Boolean; {True to dump log in hex}
{Options}
FUseMSRShadow : Boolean; {True to use MSR shadow reg}
FForceGets : Boolean; {True to force GetChar to get}
FUseEventWord : Boolean; {True to use the EventWord}
{Triggers}
FTriggerLength : Word; {Number of byte for avail trigger}
FOnTrigger : TTriggerEvent; {All-encompassing event handler}
FOnTriggerAvail : TTriggerAvailEvent; {APW_TRIGGERAVAIL events}
FOnTriggerData : TTriggerDataEvent; {APW_TRIGGERDATA events}
FOnTriggerStatus : TTriggerStatusEvent; {APW_TRIGGERSTATUS events}
FOnTriggerTimer : TTriggerTimerEvent; {APW_TRIGGERTIMER events}
FOnTriggerLineError : TTriggerLineErrorEvent; {Got line error}
FOnTriggerModemStatus : TNotifyEvent; {Got modem status change}
FOnTriggerOutbuffFree : TNotifyEvent; {Outbuff free above mark}
FOnTriggerOutbuffUsed : TNotifyEvent; {Outbuff used above mark}
FOnTriggerOutSent : TNotifyEvent; {Data was transmitted}
FOnPortOpen : TNotifyEvent; {Port just opened}
FOnPortClose : TNotifyEvent; {Port just closed}
FOnWaitChar : TWaitCharEvent; {Received char during wait}
{Property read/write methods}
procedure SetDeviceLayer(const NewDevice : TDeviceLayer);
procedure SetComNumber(const NewNumber : Word);
procedure SetBaud(const NewBaud : Longint);
procedure SetParity(const NewParity : TParity);
procedure SetDatabits(const NewBits : Word);
procedure SetStopbits(const NewBits : Word);
procedure SetInSize(const NewSize : Word);
procedure SetOutSize(const NewSize : Word);
procedure SetTracing(const NewState : TTraceLogState);
procedure SetTraceSize(const NewSize : Word);
procedure SetLogging(const NewState : TTraceLogState);
procedure SetLogSize(const NewSize : Word);
procedure SetOpen(const Enable : Boolean);
procedure SetDispatcherMode(const NewMode : TDispatcherMode);
procedure SetHWFlowOptions(const NewOpts : THWFlowOptionSet);
function GetFlowState : TFlowControlState;
procedure SetSWFlowOptions(const NewOpts : TSWFlowOptions);
procedure SetXonChar(const NewChar : Char);
procedure SetXoffChar(const NewChar : Char);
procedure SetBufferFull(const NewFull : Word);
procedure SetBufferResume(const NewResume : Word);
procedure SetTriggerLength(const NewLength : Word);
procedure SetDTR(const NewDTR : Boolean);
procedure SetRTS(const NewRTS : Boolean);
function GetComHandle : TComHandle;
function GetModemStatus : Byte;
function GetDSR : Boolean;
function GetCTS : Boolean;
function GetRI : Boolean;
function GetDCD : Boolean;
function GetDeltaDSR : Boolean;
function GetDeltaCTS : Boolean;
function GetDeltaRI : Boolean;
function GetDeltaDCD : Boolean;
function GetLineError : Word;
function GetLineBreak : Boolean;
function GetInBuffUsed : Word;
function GetInBuffFree : Word;
function GetOutBuffUsed : Word;
function GetOutBuffFree : Word;
procedure SetUseMSRShadow(NewUse : Boolean);
procedure SetForceGets(NewForce : Boolean);
procedure SetUseEventWord(NewUse : Boolean);
procedure SetCommNotificationLevel(NewLevel : Word);
protected
{Misc}
procedure Loaded; override;
{Trigger event methods}
procedure Trigger(Msg, TriggerHandle, Data : Word); virtual;
procedure TriggerAvail(Count : Word); virtual;
procedure TriggerData(TriggerHandle : Word); virtual;
procedure TriggerStatus(TriggerHandle : Word); virtual;
procedure TriggerTimer(TriggerHandle : Word); virtual;
{Port open/close/change event methods}
procedure PortOpen; dynamic;
procedure PortClose; dynamic;
{Status trigger methods}
procedure TriggerLineError(const Error : Word;
const LineBreak : Boolean); virtual;
procedure TriggerModemStatus; virtual;
procedure TriggerOutbuffFree; virtual;
procedure TriggerOutbuffUsed; virtual;
procedure TriggerOutSent; virtual;
{Wait trigger method}
procedure WaitChar(C : Char); virtual;
{Tracing}
procedure InitTracing(const NumEntries : Word);
procedure DumpTrace(const FName : String; const InHex : Boolean);
procedure AppendTrace(const FName : String; const InHex : Boolean);
procedure ClearTracing;
procedure AbortTracing;
procedure StartTracing;
procedure StopTracing;
{DispatchLogging}
procedure InitLogging(const Size : Word);
procedure DumpLog(const FName : String; const InHex : Boolean);
procedure AppendLog(const FName : String; const InHex : Boolean);
procedure ClearLogging;
procedure AbortLogging;
procedure StartLogging;
procedure StopLogging;
public
{Creation/destruction}
constructor Create(AOwner : TComponent); override;
{-Create a TApdComPort component}
destructor Destroy; override;
{-Destroy a TApdComPort component}
{General}
procedure InitPort; dynamic;
{-Physically open the serial port}
procedure DonePort; dynamic;
{-Physically close the serial port}
procedure Assign(Source: TPersistent); override;
{-Assign fields from TApdComPort object specified by Source}
procedure ForcePortOpen;
{-Force the port open after it is loaded}
procedure SendBreak(Ticks : Word; Yield : Boolean);
{-Send a line break of ticks duration}
{.Z-}
procedure RegisterUser(const H : THandle);
{-Register a TApdComPort user to receive PortOpen/PortClose events}
procedure RegisterUserCallback(CallBack : TPortCallback); {!!.01}
{-Register a TApdComPort user to receive callbacks} {!!.01}
procedure DeregisterUser(const H : THandle);
{-Deregister a TApdComPort user from receiving PortOpen/PortClose events}
procedure DeregisterUserCallback(CallBack : TPortCallback); {!!.01}
{-Deregister a TApdComPort user callback} {!!.01}
procedure ProcessCommunications; virtual;
{-Call the internal dispatcher}
procedure FlushInBuffer;
{-Discard the contents of the input buffer}
procedure FlushOutBuffer;
{-Discard the contents of the output buffer}
procedure RegisterTriggerHandler(H : HWnd; NP : TNotifyProc);
{-Register a window or TNotifyProc as a recipient of trigger messages}
procedure DeregisterTriggerHandler(H : HWnd; NP : TNotifyProc);
{-Deregister a trigger handler}
{Trigger managment}
function AddDataTrigger(const Data : ShortString; {!!.01}
const IgnoreCase : Boolean) : Word;
{-Add a data trigger}
function AddTimerTrigger : Word;
{-Add a timer trigger}
function AddStatusTrigger(const SType : Word) : Word;
{-Add a status trigger}
procedure RemoveTrigger(const Handle : Word);
{-Remove a trigger}
procedure RemoveAllTriggers;
{-Remove all triggers}
procedure SetTimerTrigger(const Handle : Word; const Ticks : LongInt;
const Activate : Boolean);
{-Activate or deactivate a timer trigger}
procedure SetStatusTrigger(const Handle : Word; const Value : Word;
const Activate : Boolean);
{-Activate or deactivate a status trigger}
{I/O}
function CharReady : Boolean;
{-Return True if at least one character is in the input buffer}
function PeekChar(const Count : Word) : Char;
{-Return a received character other than the next one}
function GetChar : Char;
{-Return the next received character}
procedure PeekBlock(var Block; const Len : Word);
{-Return a block of data other than the next block}
procedure GetBlock(var Block; const Len : Word);
{-Return the next block of data}
procedure PutChar(const C : Char);
{-Add C to the output buffer}
procedure PutString(const S : String);
{-Add S to the output buffer}
function PutBlock(const Block; const Len : Word) : Integer;
{-Add Block to the output buffer}
{Waits}
function CheckForString(var Index : Byte; C : Char;
const S : String;
IgnoreCase : Boolean) : Boolean;
{-Compare C against a sequence of chars, looking for S}
function WaitForString(const S : String;
const Timeout : LongInt;
const Yield, IgnoreCase : Boolean) : Boolean;
{-Wait for S}
function WaitForMultiString(const S : String; const Timeout : LongInt;
const Yield, IgnoreCase : Boolean;
const SepChar : Char) : Integer;
{-Wait for S, which contains several substrings separated by ^}
{Port parameter properties}
property DeviceLayer : TDeviceLayer
read FDeviceLayer write SetDeviceLayer default DefDeviceLayer;
property ComNumber : Word
read FComNumber write SetComNumber default DefComNumber;
property Baud : LongInt
read FBaud write SetBaud default DefBaud;
property Parity : TParity
read FParity write SetParity default DefParity;
property DataBits : Word
read FDatabits write SetDatabits default DefDatabits;
property StopBits : Word
read FStopbits write SetStopbits default DefStopbits;
{Miscellaneous port properties}
property InSize : Word
read FInSize write SetInSize default DefInSize;
property OutSize : Word
read FOutSize write SetOutSize default DefOutSize;
property Open : Boolean
read FOpen write SetOpen default DefOpen;
property AutoOpen : Boolean
read FAutoOpen write FAutoOpen default DefAutoOpen;
property DispatcherMode : TDispatcherMode
read FDispatcherMode write SetDispatcherMode default DefDispatcherMode;
property CommNotificationLevel : Word
read FCommNotificationLevel write SetCommNotificationLevel
default DefCommNotificationLevel;
{Modem control/status}
property DTR : Boolean
read FDTR write SetDTR default DefDTR;
property RTS : Boolean
read FRTS write SetRTS default DefRTS;
{Flow control properties}
property HWFlowOptions : THWFlowOptionSet
read FHWFlowOptions write SetHWFlowOptions default DefHWFlowOptions;
property FlowState : TFlowControlState
read GetFlowState;
property SWFlowOptions : TSWFlowOptions
read FSWFlowOptions write SetSWFlowOptions default DefSWFlowOptions;
property XOnChar : Char
read FXonChar write SetXonChar default DefXOnChar;
property XOffChar : Char
read FXOffChar write SetXoffChar default DefXOffChar;
property BufferFull : Word
read FBufferFull write SetBufferFull default DefBufferFull;
property BufferResume : Word
read FBufferResume write SetBufferResume default DefBufferResume;
{Debugging}
property Tracing : TTraceLogState
read FTracing write SetTracing default DefTracing;
property TraceSize : Word
read FTraceSize write SetTraceSize default DefTraceSize;
property TraceName : String
read FTraceName write FTraceName;
property TraceHex : Boolean
read FTraceHex write FTraceHex default DefTraceHex;
property Logging : TTraceLogState
read FLogging write SetLogging default DefLogging;
property LogSize : Word
read FLogSize write SetLogSize default DefLogSize;
property LogName : String
read FLogName write FLogName;
property LogHex : Boolean
read FLogHex write FLogHex default DefLogHex;
{Options}
property UseMSRShadow : Boolean
read FUseMSRShadow write SetUseMSRShadow default DefUseMSRShadow;
property ForceGets : Boolean
read FForceGets write SetForceGets default DefForceGets;
property UseEventWord : Boolean
read FUseEventWord write SetUseEventWord default DefUseEventWord;
{Tracing}
procedure AddTraceEntry(const CurEntry, CurCh : Char);
{-Add an entry to the trace buffer}
{Trigger events}
property TriggerLength : Word
read FTriggerLength write SetTriggerLength default DefTriggerLength;
property OnTrigger : TTriggerEvent
read FOnTrigger write FOnTrigger;
property OnTriggerAvail : TTriggerAvailEvent
read FOnTriggerAvail write FOnTriggerAvail;
property OnTriggerData : TTriggerDataEvent
read FOnTriggerData write FOnTriggerData;
property OnTriggerStatus : TTriggerStatusEvent
read FOnTriggerStatus write FOnTriggerStatus;
property OnTriggerTimer : TTriggerTimerEvent
read FOnTriggerTimer write FOnTriggerTimer;
{.Z+}
{Port open/close/change events}
property OnPortOpen : TNotifyEvent
read FOnPortOpen write FOnPortOpen;
property OnPortClose : TNotifyEvent
read FOnPortClose write FOnPortClose;
{.Z-}
{Status events}
property OnTriggerLineError : TTriggerLineErrorEvent
read FOnTriggerLineError write FOnTriggerLineError;
property OnTriggerModemStatus : TNotifyEvent
read FOnTriggerModemStatus write FOnTriggerModemStatus;
property OnTriggerOutbuffFree : TNotifyEvent
read FOnTriggerOutbuffFree write FOnTriggerOutbuffFree;
property OnTriggerOutbuffUsed : TNotifyEvent
read FOnTriggerOutbuffUsed write FOnTriggerOutbuffUsed;
property OnTriggerOutSent : TNotifyEvent
read FOnTriggerOutSent write FOnTriggerOutSent;
{WaitChar event}
property OnWaitChar : TWaitCharEvent
read FOnWaitchar write FOnWaitChar;
{Device layer activation property}
property ActivateDevice : TActivationProcedure
read FActivateDevice write FActivateDevice;
{I/O properties}
property Output : String
write PutString;
{TComHandle, read only}
property ComHandle : Word
read GetComHandle default DefComHandle;
{Modem status, read only}
property ModemStatus : Byte
read GetModemStatus;
property DSR : Boolean
read GetDSR;
property CTS : Boolean
read GetCTS;
property RI : Boolean
read GetRI;
property DCD : Boolean
read GetDCD;
property DeltaDSR : Boolean
read GetDeltaDSR;
property DeltaCTS : Boolean
read GetDeltaCTS;
property DeltaRI : Boolean
read GetDeltaRI;
property DeltaDCD : Boolean
read GetDeltaDCD;
{Line errors}
property LineError : Word
read GetLineError;
property LineBreak : Boolean
read GetLineBreak;
{Buffer info, readonly}
property InBuffUsed : Word
read GetInBuffUsed;
property InBuffFree : Word
read GetInBuffFree;
property OutBuffUsed : Word
read GetOutBuffUsed;
property OutBuffFree : Word
read GetOutBuffFree;
end;
{Port component}
TApdComPort = class(TApdCustomComPort)
published
property DeviceLayer;
property ComNumber;
property Baud;
property Parity;
property DataBits;
property StopBits;
property InSize;
property OutSize;
property AutoOpen;
property DispatcherMode;
property Open;
property DTR;
property RTS;
property HWFlowOptions;
property SWFlowOptions;
property XOnChar;
property XOffChar;
property BufferFull;
property BufferResume;
property Tracing;
property TraceSize;
property TraceName;
property TraceHex;
property Logging;
property LogSize;
property LogName;
property LogHex;
property UseMSRShadow;
property ForceGets;
property UseEventWord;
property TriggerLength;
property CommNotificationLevel;
property OnTrigger;
property OnTriggerAvail;
property OnTriggerData;
property OnTriggerStatus;
property OnTriggerTimer;
property OnTriggerLineError;
property OnTriggerModemStatus;
property OnTriggerOutbuffFree;
property OnTriggerOutbuffUsed;
property OnTriggerOutSent;
property OnWaitChar;
property Tag;
end;
function ErrorMsg(const ErrorCode : SmallInt) : String;
function ComName(const ComNumber : Word) : String;
{.Z+}
function SearchComPort(const C : TComponent) : TApdCustomComPort;
procedure Register;
{.Z-}